
//
//  UIButton+Extension.swift
//  sinaweiboFirst
//
//  Created by mac on 16/3/10.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit

extension UIButton {
    //背景图片+ 文字 按钮格式
    class func buttonWithTitle(title: String,backImageName: String?,textColor: UIColor,fontSize: CGFloat,imageName: String? = nil) -> UIButton {
        
        let btn = UIButton()
        if backImageName != nil {
            btn.setBackgroundImage(UIImage(named: backImageName!), forState: .Normal)
        }
        
        if imageName != nil {
            btn.setImage(UIImage(named: imageName!), forState: .Normal)
        }
        
        btn.setTitle(title, forState: .Normal)
        btn.setTitleColor(textColor, forState: .Normal)
        btn.titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        btn.sizeToFit()
        return btn
    }
    //背景图片＋ 图片 按钮格式
    class func buttonWithImage(imageName: String?,backImageName: String?) -> UIButton {
        
        let btn = UIButton()
        if backImageName != nil {
            btn.setBackgroundImage(UIImage(named: backImageName!), forState: .Normal)
            btn.setBackgroundImage(UIImage(named: backImageName! + "_highlighted"), forState: .Selected)
        }
        
        if imageName != nil {
            btn.setImage(UIImage(named: imageName!), forState: .Normal)
            btn.setImage(UIImage(named: imageName! + "_highlighted"), forState: .Selected)
        }
        
        btn.sizeToFit()
        return btn

    }



}




























